package com.itxx.test.Demo1;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.net.Socket;

//客户端(发送端)
public class TcpSend {
    public static void main(String[] args) throws IOException {
       //创建Socket对象
        Socket socket = new Socket("127.0.0.1", 34567);
        //创建字符缓冲流输出流
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
           //写出数据
          bw.write("你好,世界,这是通过tcp协议传输的数据");

          bw.flush();
          //释放资源
       socket.close();
     /* try(  Socket socket = new Socket("127.0.0.1", 34567);
            //创建字符缓冲流输出流
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));){
          //写出数据
          bw.write("你好,世界,这是通过tcp协议传输的数据");

          bw.flush();
      }*/
    }
}
